package com.customer.controller.driver;


import com.alibaba.fastjson.JSON;
import com.aop.SysLog;
import com.customer.model.Driver;
import com.customer.service.driver.DriverService;
import com.customer.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/driverAdmin")
public class DriverAdminController {

    @Autowired
    private DriverService driverService;

    @RequestMapping("/driverInfo")
    public String customerInfo(){
        return "/driver/driverInfo.html";
    }

    @RequestMapping("/driverUpdate")
    public String customerUpdate(){
        return "/driver/driverUpdate.html";
    }

    @RequestMapping("/driverShow")
    @SysLog(operation = "跳转修改司机页" , method = "driverShow_page" , module = "后端管理")
    public String customerShow(){
        return "/driver/driverShow.html";
    }

    @ResponseBody
    @RequestMapping("/showDriver")
    @SysLog(operation = "查询全部司机" , method = "showDriver" , module = "后端管理")
    public String showDriver(int page, int limit, @RequestParam(required = true, defaultValue = "") String phoneNumber) {
        ResponseData responseData = driverService.findAllByPage(page, limit, phoneNumber);
        System.out.println(responseData);
        return JSON.toJSONString(responseData);
    }

    @ResponseBody
    @RequestMapping("/updateShow")
    @SysLog(operation = "查询修改司机" , method = "update_showDriver" , module = "后端管理")
    public String updateShow(@RequestParam int id){
        ResponseData responseData = driverService.updateShow(id);
        return JSON.toJSONString(responseData) ;
    }

    @ResponseBody
    @RequestMapping("/update")
    public String update( Driver driver ){
        System.out.println(driver);
        ResponseData responseData = driverService.update(driver);
        return JSON.toJSONString(responseData);
    }

    @ResponseBody
    @RequestMapping("/deleteDriver")
    @SysLog(operation = "删除司机" , method = "deleteDriver" , module = "后端管理")
    public String deleteDriver(int id){
        ResponseData responseData = driverService.deleteDriver(id);
        return JSON.toJSONString(responseData);
    }
}